package com.legendshop.openportal.sdk.model.message;

import com.legendshop.openportal.sdk.utils.signer.ContentSigner;
import lombok.Builder;
import lombok.Data;

/**
 * 平台标准的推送消息
 * @author chan
 */
@Data
@Builder
public class StandardMessageWrap implements MessageWrap, SignContent {

    /**
     * 消息id
     */
    private String messageId;

    /**
     * 应用id
     */
    private String appId;

    /**
     * 是否测试消息
     */
    private Boolean test;

    /**
     * 消息来源
     */
    private String messageSource;

    /**
     * 消息类型
     */
    private String messageType;

    /**
     * 是否加密
     */
    private Boolean encryption;

    /**
     * 加密类型
     */
    private String encryptionType;

    /**
     * 消息体
     */
    private String messageBody;

    /**
     * 消息生成时间
     */
    private Long messageTime;

    /**
     * 签名
     */
    private String sign;

    /**
     * 随机串
     */
    private String nonce;

    /**
     * 时间戳
     */
    private Long timestamp;

    public StandardMessageWrap buildSign(ContentSigner contentSigner, String secretKey) {
        this.setSign(contentSigner.buildSign(this, secretKey));
        return this;
    }

    @Override
    public String getSignStr() {
        return sign;
    }

    @Override
    public void setSignStr(String sign) {
        this.sign = sign;
    }

    @Override
    public boolean expired() {
        return false;
    }
}
